package com.gxa.admin.recycling.controller;
import com.gxa.admin.recycling.service.UserService;
import com.gxa.core.recycling.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService=null;
    @PostMapping("/findUser")
    @ApiOperation("查询全部用户")
    public Map findAll(@RequestParam("page") Integer page,@RequestParam("size") Integer size,
                       Long uid, String phone, String username,String provinces, Long cid) throws IllegalAccessException {

        JsonResult jsonResult=new JsonResult();
        Map<Integer, List<Map>> userByPage = userService.findUserByPage(uid, phone, username,provinces, cid, page, size);

        Set<Integer> integers = userByPage.keySet();

        for (Integer integer : integers) {
            jsonResult.setCode("200");
            jsonResult.setData(userByPage.get(integer));
            jsonResult.put("total",integer);
        }

        return jsonResult.getDataMap();
    }

    @PostMapping("/findUserById")
    @ApiOperation("根据用户id查询用户")
    public Map findUserById(@RequestParam("id") @NotNull Long id){
        Map userById = userService.findUserById(id);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(userById);
        return jsonResult.getDataMap();
    }


}
